<!DOCTYPE html>
<html>
  <head>
    <!-- [[! Document Settings ]] -->
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <!-- [[! Page Meta ]] -->
    <title>在 macOS 上使用 Docker Desktop 启动 Kubernetes</title>
    <meta name="description" content="在编码 - " />

    <meta name="HandheldFriendly" content="True" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link rel="shortcut icon" href="/assets/images/favicon.ico" >

    <!-- [[! Styles'n'Scripts ]] -->
    <link rel="stylesheet" type="text/css" href="/assets/css/screen.css" />
    <link rel="stylesheet" type="text/css"
      href="//fonts.googleapis.com/css?family=Merriweather:300,700,700italic,300italic|Open+Sans:700,400" />

    <link rel="stylesheet" type="text/css" href="/assets/css/prism.css" />

    <!-- [[! Ghost outputs important style and meta data with this tag ]] -->
    <link rel="canonical" href="/" />
<meta name="referrer" content="origin" />
<link rel="next" href="/page2/" />

<meta property="og:site_name" content="在编码" />
<meta property="og:type" content="website" />
<meta property="og:title" content="在编码" />
<meta property="og:description" content="" />
<meta property="og:url" content="/" />
<meta property="og:image" content="/assets/images/cover1.jpg" />

<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="在编码" />
<meta name="twitter:description" content="" />
<meta name="twitter:url" content="/" />
<meta name="twitter:image:src" content="/assets/images/cover1.jpg" />

<script type="application/ld+json">
  {
  "@context": "http://schema.org",
  "@type": "Website",
  "publisher": "Finding The Way Home",
  "url": "/",
  "image": "/assets/images/cover1.jpg",
  "description": ""
  }
</script>

<meta name="generator" content="Jekyll 3.0.0" />
<link rel="alternate" type="application/rss+xml" title="在编码" href="/feed.xml" />


  </head>
  <body class="home-template nav-closed">

    <div class="nav">
  <h3 class="nav-title">Home</h3>
  <a href="#" class="nav-close">
    <span class="hidden">Close</span>
  </a>
  <ul>
    <li class="nav-home " role="presentation"><a href="/">Home</a></li>
    <!-- <li class="nav-about " role="presentation"><a href="/about">About</a></li>
    <li class="nav-author " role="presentation"><a href="/author/casper">Author</a></li> -->
    <li class="nav-ios " role="presentation"><a href="/tag/iOS">iOS</a></li>
    <li class="nav-mvc " role="presentation"><a href="/tag/Android">Android</a></li>
    <li class="nav-server " role="presentation"><a href="/tag/Server">Server</a></li>
  </ul>
  <a class="subscribe-button icon-feed" href="/feed.xml">Subscribe</a>
</div>
<span class="nav-cover"></span>


    <div class="site-wrapper">

      <!-- [[! Everything else gets inserted here ]] -->
      <!-- < default -->

<!-- The comment above "< default" means - insert everything in this file into -->
<!-- the [body] of the default.hbs template, which contains our header/footer. -->

<!-- Everything inside the #post tags pulls data from the post -->
<!-- #post -->

<header class="main-header post-head no-cover">
  <nav class="main-nav overlay clearfix">
      <a class="back-button icon-arrow-left" href='/'>Home</a>
    <a class="menu-button icon-menu" href="#"><span class="word">Menu</span></a>
  </nav>
</header>

<main class="content" role="main">

  <article class="post">

    <header class="post-header">
      <h1 class="post-title">在 macOS 上使用 Docker Desktop 启动 Kubernetes</h1>
      <section class="post-meta">
        <a href='/'>Listen</a>
        <time class="post-date" datetime="2020-02-29">29 Feb 2020</time>
        <!-- [[tags prefix=" on "]] -->
        
        on
        
        
        <a href='/tag/k8s'>k8s</a>
        
        
        
      </section>
    </header>

    <section class="post-content">

      <p>在中国做程序员真难，经过几天的折腾，终于成功在 macOS 上使用 Docker Desktop 启动 Kubernetes，特此记录。</p>

<h2>为 Docker for Mac 配置 HTTP 代理</h2>

<p>根据<a href="https://zhuanlan.zhihu.com/p/26033249">这篇文章</a>指引，为 Docker for Mac 配置 HTTP 代理</p>

<ul>
<li>我使用的代理软件是 Shadowsocks, 将 HTTP 代理监听地址和本地 sock5 监听地址设置为 <code>0.0.0.0</code></li>
</ul>

<p><img src="../images/k8s/http_proxy.png" alt=""></p>

<p><img src="../images/k8s/socks5_proxy.png" alt=""></p>

<ul>
<li>将本机的 lo0 网络接口设置成任意 IP</li>
</ul>
<figure class="highlight"><pre><code class="language-text" data-lang="text">sudo ifconfig lo0 alias 10.200.10.1/24
</code></pre></figure>
<ul>
<li>设置开机自动设置 lo0 网络 alias</li>
</ul>

<p>新建文件 lo0_alias.sh，内容如下</p>
<figure class="highlight"><pre><code class="language-sh" data-lang="sh">#!/bin/sh
sudo ifconfig lo0 alias 10.200.10.1/24
</code></pre></figure>
<p>赋予执行权限</p>
<figure class="highlight"><pre><code class="language-sh" data-lang="sh">chmod +x ./lo0_alias.sh
</code></pre></figure>
<p>将该文件加入开机自启动</p>
<figure class="highlight"><pre><code class="language-sh" data-lang="sh">sudo defaults write com.apple.loginwindow LoginHook ~/cmd/lo0_alias.sh
</code></pre></figure>
<p>我把 lo0_alias.sh 保存在了用户目录下的 cmd 目录内</p>

<p><img src="../images/k8s/cmd_location.png" alt=""></p>

<ul>
<li>在 Docker for Mac 里设置代理</li>
</ul>

<p><img src="../images/k8s/docker_http_proxy.png" alt=""></p>

<h2>安装 Kubenetes</h2>

<p>开启全局代理</p>

<p><img src="../images/k8s/shadowsocks_globel.png" alt=""></p>

<p>开启 Kubenetes</p>

<p><img src="../images/k8s/enable_k8s.png" alt=""></p>

<p>可以不定时通过 <code>docker image ls</code> 来查看进度</p>

<p><img src="../images/k8s/ls_docker_image.png" alt=""></p>

<h2>Install kubectl on macOS</h2>

<p>根据官方指引，<a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-macos">安装 kubectl</a></p>
<figure class="highlight"><pre><code class="language-text" data-lang="text">export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;

curl -LO &quot;https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl&quot;

chmod +x ./kubectl

sudo mv ./kubectl /usr/local/bin/kubectl

export no_proxy=127.0.0.1,localhost,kubernetes.docker.internal

kubectl version
</code></pre></figure>
<h2>安装 Dashboard</h2>

<p><a href="https://github.com/kubernetes/dashboard">Kubernetes Dashboard</a> 是 Kubernetes 集群可视化的仪表盘。</p>

<p>通过以下命令安装 Dashboard：</p>
<figure class="highlight"><pre><code class="language-text" data-lang="text">export http_proxy=127.0.0.1:1087
export https_proxy=127.0.0.1:1087
export no_proxy=127.0.0.1,localhost,kubernetes.docker.internal

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-rc5/aio/deploy/recommended.yaml
</code></pre></figure>
<p>需要等待 Dashboard 的镜像拉取完毕</p>

<p>通过 <code>docker image ls</code> 命令查看，如果发现 <code>kubernetesui/dashboard</code> 和 <code>kubernetesui/metrics-scraper</code> 这两个镜像已经拉取完毕，稍后可以通过以下命令启动 Dashboard：</p>
<figure class="highlight"><pre><code class="language-text" data-lang="text">kubectl proxy
</code></pre></figure>
<p>启动成功后，可以通过该地址进行访问 Dashboard：</p>

<p>http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/</p>

<p><img src="../images/k8s/dashboard.png" alt=""></p>

<p>进入 Dashboard 需要令牌，可以通过以下命令获取令牌：</p>
<figure class="highlight"><pre><code class="language-text" data-lang="text">kubectl -n kube-system describe secret default| awk &#39;$1==&quot;token:&quot;{print $2}&#39;
</code></pre></figure>

    </section>

    <footer class="post-footer">

      <!-- Everything inside the #author tags pulls data from the author -->
      <!-- #author-->

      
      <figure class="author-image">
        <a class="img" href='/' style="background-image: url(/assets/images/me.jpg)"><span class="hidden">'s Picture</span></a>
      </figure>
      

      <section class="author">
        <h4><a href='/'>Listen</a></h4>

        
        <p> 移动开发工程师，熟悉 Android、iOS、ReactNative</p>
        
        <div class="author-meta">
          <span class="author-location icon-location"> 深圳</span>
          <span class="author-link icon-link"><a href="https://github.com/listenzz"> Github</a></span>
        </div>
      </section>

      <!-- /author  -->

      <section class="share">
        <h4>Share this post</h4>
        <a class="icon-twitter" href="http://twitter.com/share?text=在 macOS 上使用 Docker Desktop 启动 Kubernetes&amp;url=https://github.com/listenzzhow-to-enable-k8s-from-docker-desktop.html"
          onclick="window.open(this.href, 'twitter-share', 'width=550,height=235');return false;">
          <span class="hidden">Twitter</span>
        </a>
        <a class="icon-facebook" href="https://www.facebook.com/sharer/sharer.php?u=https://github.com/listenzzhow-to-enable-k8s-from-docker-desktop.html"
          onclick="window.open(this.href, 'facebook-share','width=580,height=296');return false;">
          <span class="hidden">Facebook</span>
        </a>
        <a class="icon-google-plus" href="https://plus.google.com/share?url=https://github.com/listenzzhow-to-enable-k8s-from-docker-desktop.html"
          onclick="window.open(this.href, 'google-plus-share', 'width=490,height=530');return false;">
          <span class="hidden">Google+</span>
        </a>
      </section>

      <!-- Add Disqus Comments -->
      <!-- <section class="disqus">
    <div id="disqus_thread"></div>
    <script type="text/javascript">
        var disqus_shortname  = 'listenzz';
        var disqus_identifier = '在 macOS 上使用 Docker Desktop 启动 Kubernetes';
        var disqus_title      = "在 macOS 上使用 Docker Desktop 启动 Kubernetes";
        
        (function() {
         var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
         dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
         (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
         })();
        </script>
    <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
</section>
 -->

    </footer>

  </article>

</main>

<aside class="read-next">

  <!-- [[! next_post ]] -->
  
  <!-- [[! /next_post ]] -->
  <!-- [[! prev_post ]] -->
  
  <a class="read-next-story prev no-cover" href="/android-lifecyle-works-perfectly-with-rxjava.html">
    <section class="post">
      <h2>Android 生命周期架构组件与 RxJava 完美协作</h2>
      <p>本文主要讲述了 Android 生命周期架构组件如何与 RxJava 协作，从此过上了幸福生活的故事。 涉及的内容有： Android 生命周期架构组件 LiveData 有哪些惊艳特性 如何使用 RxJava 中的 Observable 代替...</p>
    </section>
  </a>
  
  <!-- [[! /prev_post ]] -->
</aside>

<!-- /post -->


      <footer class="site-footer clearfix">
        <section class="copyright"><a href="/">在编码</a> &copy; 2020</section>
        <section class="poweredby">Proudly published with <a href="https://jekyllrb.com/">Jekyll</a> using <a href="https://github.com/biomadeira/jasper">Jasper</a></section>
      </footer>
    </div>
    <!-- [[! Ghost outputs important scripts and data with this tag ]] -->
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
    <!-- [[! The main JavaScript file for Casper ]] -->
    <script type="text/javascript" src="/assets/js/jquery.fitvids.js"></script>
    <script type="text/javascript" src="/assets/js/index.js"></script>
    <script type="text/javascript" src="/assets/js/prism.js"></script>

    <!-- Add Google Analytics  -->
    <!-- Google Analytics Tracking code -->
<script>
 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
   (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
   m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

 ga('create', 'UA-96120107-1', 'auto');
 ga('send', 'pageview');

</script>

  </body>
</html>
